package cn.iocoder.ny.module.mall.mapper;

import cn.iocoder.ny.module.mall.controller.admin.product.vo.MallProductOrderVo;
import cn.iocoder.ny.module.mall.domain.MallProductSpecification;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MallProductSpecificationMapper extends BaseMapper<MallProductSpecification> {
    int updateBatch(List<MallProductSpecification> list);

    int updateBatchSelective(List<MallProductSpecification> list);

    int batchInsert(@Param("list") List<MallProductSpecification> list);

    MallProductOrderVo queryBySpecificationId(Long spectionId);




    @Update("UPDATE mall_product_specification " +
            "SET stock = stock - #{stock} " +
            "WHERE id = #{specificationId} " +
            "AND EXISTS (SELECT 1 FROM mall_order " +
            "            WHERE mall_order.status = 10 " +
            "            AND mall_order.order_id = #{orderId})")
    int updateStockBySpecIdAndOrderStatus(@Param("stock") Integer stock, @Param("specificationId") Long specificationId, @Param("orderId") Long orderId);

}